package cn.vcjf.weapp.api.goods.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.vcjf.weapp.common.web.TableResult;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import cn.vcjf.weapp.api.goods.entity.GoodsOrderItem;
import cn.vcjf.weapp.api.goods.service.GoodsOrderItemService;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhengzihang
 * @since 2018-09-27
 */
@Controller
@RequestMapping("/goods/goodsOrderItem")
public class GoodsOrderItemController {
     @Resource
     private GoodsOrderItemService  goodsOrderItemService;

     @RequestMapping("/addGoodsOrderItem")
     @ResponseBody
     public TableResult addGoodsOrderItem(GoodsOrderItem goodsOrderItem){
         goodsOrderItem.preInsert();
         boolean b = goodsOrderItemService.insert(goodsOrderItem);
         return TableResult.Result(b);
     }

     @RequestMapping("/updateGoodsOrderItem")
     @ResponseBody
     public TableResult updateGoodsOrderItem(GoodsOrderItem goodsOrderItem){
         goodsOrderItem.preUpdate();
         boolean b = goodsOrderItemService.updateById(goodsOrderItem);
         return TableResult.Result(b);
     }

     @RequestMapping("/findGoodsOrderItemOne")
     @ResponseBody
     public TableResult findGoodsOrderItemOne(GoodsOrderItem goodsOrderItem){

        EntityWrapper<GoodsOrderItem> wrapper = goodsOrderItem.getQueryWrapper();
        //Todo

        GoodsOrderItem result = goodsOrderItemService.selectOne(wrapper);

		return TableResult.OKResult(result);
     }

     @RequestMapping("/findGoodsOrderItemList")
     @ResponseBody
     public TableResult findGoodsOrderItemList(GoodsOrderItem goodsOrderItem){

        EntityWrapper<GoodsOrderItem> wrapper = goodsOrderItem.getQueryWrapper();
        //Todo

        Page<GoodsOrderItem> page = goodsOrderItem.getPageInfo();

        List<GoodsOrderItem> list = goodsOrderItemService.selectOrderItemPage(goodsOrderItem);
         page.setRecords(list);

		return TableResult.OKResult(page);

     }

     @RequestMapping("/deleteGoodsOrderItem")
     @ResponseBody
     public TableResult deleteGoodsOrderItem(GoodsOrderItem goodsOrderItem){
        goodsOrderItem.preUpdate();
        boolean b = goodsOrderItemService.deleteById(goodsOrderItem.getId());
        return TableResult.Result(b);
     }

}
